package cn.mumzone.basic.util;

import android.view.View;

import cn.mumzone.basic.R;

/**
 * Created By Dlx
 * on 2019/5/9
 */
public class IsFastClickUtil {
    private static final int MIN_DELAY_TIME = 1000;  // 两次点击间隔不能少于1000ms
    private static long lastClickTime;

    public static boolean isFastClick() {
        boolean flag = true;
        long currentClickTime = System.currentTimeMillis();
        if ((currentClickTime - lastClickTime) >= MIN_DELAY_TIME) {
            flag = false;
        }
        lastClickTime = currentClickTime;
        return flag;
    }

    public static boolean isFastClick(View view) {
        long currentClickTime = System.currentTimeMillis();

        if (null == view.getTag(R.id.fast_click_id)) {
            view.setTag(R.id.fast_click_id, currentClickTime);
            return false;
        }

        long lastClickTime = (long) view.getTag(R.id.fast_click_id);
        if ((currentClickTime - lastClickTime) >= MIN_DELAY_TIME) {
            view.setTag(R.id.fast_click_id, currentClickTime);
            return false;
        }
        return true;
    }
}
